]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool: Add list options
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 27 Aug 2018 04:16:54 +0000 (06:16 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 21 Aug 2019 16:28:02 +0000 (18:28 +0200)
In addition to a plain list of all extensions, add options to display
additional details of each extensions and to filter the list by
enabled state or install location.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234

src/extensions-tool/command-list.c
src/extensions-tool/common.h
src/extensions-tool/main.c

index e97360de20be6acd9808c27bdad818e3a0c05fc9..0313cd93c1b504c641554580eb5c6ba362189d1d 100644 (file)
 
 #include "commands.h"
 #include "common.h"
+#include "config.h"
+
+
+typedef enum {
+  LIST_FLAGS_NONE     = 0,
+  LIST_FLAGS_USER     = 1 << 0,
+  LIST_FLAGS_SYSTEM   = 1 << 1,
+  LIST_FLAGS_ENABLED  = 1 << 2,
+  LIST_FLAGS_DISABLED = 1 << 3
+} ListFilterFlags;
 
 static gboolean
-list_extensions (void)
+list_extensions (ListFilterFlags filter, DisplayFormat format)
 {
   g_autoptr (GDBusProxy) proxy = NULL;
   g_autoptr (GVariant) response = NULL;
   g_autoptr (GVariant) extensions = NULL;
   g_autoptr (GError) error = NULL;
+  gboolean needs_newline = FALSE;
   GVariantIter iter;
   GVariant *value;
   char *uuid;
@@ -53,7 +64,32 @@ list_extensions (void)
 
   g_variant_iter_init (&iter, extensions);
   while (g_variant_iter_loop (&iter, "{s@a{sv}}", &uuid, &value))
-    g_print ("%s\n", uuid);
+    {
+      g_autoptr (GVariantDict) info = NULL;
+      double type, state;
+
+      info = g_variant_dict_new (value);
+      g_variant_dict_lookup (info, "type", "d", &type);
+      g_variant_dict_lookup (info, "state", "d", &state);
+
+      if (type == TYPE_USER && (filter & LIST_FLAGS_USER) == 0)
+        continue;
+
+      if (type == TYPE_SYSTEM && (filter & LIST_FLAGS_SYSTEM) == 0)
+        continue;
+
+      if (state == STATE_ENABLED && (filter & LIST_FLAGS_ENABLED) == 0)
+        continue;
+
+      if (state != STATE_ENABLED && (filter & LIST_FLAGS_DISABLED) == 0)
+        continue;
+
+      if (needs_newline)
+        g_print ("\n");
+
+      print_extension_info (info, format);
+      needs_newline = (format != DISPLAY_ONELINE);
+    }
 
   return TRUE;
 }
@@ -63,12 +99,37 @@ handle_list (int argc, char *argv[], gboolean do_help)
 {
   g_autoptr (GOptionContext) context = NULL;
   g_autoptr (GError) error = NULL;
+  int flags = LIST_FLAGS_NONE;
+  gboolean details = FALSE;
+  gboolean user = FALSE;
+  gboolean system = FALSE;
+  gboolean enabled = FALSE;
+  gboolean disabled = FALSE;
+  GOptionEntry entries[] = {
+    { .long_name = "user",
+      .arg = G_OPTION_ARG_NONE, .arg_data = &user,
+      .description = _("Show user-installed extensions") },
+    { .long_name = "system",
+      .arg = G_OPTION_ARG_NONE, .arg_data = &system,
+      .description = _("Show system-installed extensions") },
+    { .long_name = "enabled",
+      .arg = G_OPTION_ARG_NONE, .arg_data = &enabled,
+      .description = _("Show enabled extensions") },
+    { .long_name = "disabled",
+      .arg = G_OPTION_ARG_NONE, .arg_data = &disabled,
+      .description = _("Show disabled extensions") },
+    { .long_name = "details", .short_name = 'd',
+      .arg = G_OPTION_ARG_NONE, .arg_data = &details,
+      .description = _("Print extension details") },
+    { NULL }
+  };
 
   g_set_prgname ("gnome-extensions list");
 
   context = g_option_context_new (NULL);
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("List installed extensions"));
+  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
 
   if (do_help)
     {
@@ -88,5 +149,18 @@ handle_list (int argc, char *argv[], gboolean do_help)
       return 1;
     }
 
-  return list_extensions () ? 0 : 2;
+  if (user || !system)
+    flags |= LIST_FLAGS_USER;
+
+  if (system || !user)
+    flags |= LIST_FLAGS_SYSTEM;
+
+  if (enabled || !disabled)
+    flags |= LIST_FLAGS_ENABLED;
+
+  if (disabled || !enabled)
+    flags |= LIST_FLAGS_DISABLED;
+
+  return list_extensions (flags, details ? DISPLAY_DETAILED
+                                         : DISPLAY_ONELINE) ? 0 : 2;
 }
index 1c8b4cdd244d190744f9a6c762f19f3d36f3f42c..849c9caab5257071062be10a97d6818ae8b1740d 100644 (file)
 
 G_BEGIN_DECLS
 
+typedef enum {
+  TYPE_SYSTEM = 1,
+  TYPE_USER
+} ExtensionType;
+
+typedef enum {
+  STATE_ENABLED = 1,
+  STATE_DISABLED,
+  STATE_ERROR,
+  STATE_OUT_OF_DATE,
+  STATE_DOWNLOADING,
+  STATE_INITIALIZED,
+
+  STATE_UNINSTALLED = 99
+} ExtensionState;
+
+typedef enum {
+  DISPLAY_ONELINE,
+  DISPLAY_DETAILED
+} DisplayFormat;
+
 void show_help (GOptionContext *context,
                 const char     *message);
 
+void print_extension_info (GVariantDict  *info,
+                           DisplayFormat  format);
+
 GDBusProxy *get_shell_proxy (GError **error);
 GSettings  *get_shell_settings (void);
 
index f40091d2c0f94b7844bba58225a43cf65370d24b..f415e016870663556c5eb03e7f00539352d7c513 100644 (file)
 #include "commands.h"
 #include "common.h"
 
+static const char *
+extension_state_to_string (ExtensionState state)
+{
+  switch (state)
+    {
+    case STATE_ENABLED:
+      return "ENABLED";
+    case STATE_DISABLED:
+      return "DISABLED";
+    case STATE_ERROR:
+      return "ERROR";
+    case STATE_OUT_OF_DATE:
+      return "OUT OF DATE";
+    case STATE_DOWNLOADING:
+      return "DOWNLOADING";
+    case STATE_INITIALIZED:
+      return "INITIALIZED";
+    case STATE_UNINSTALLED:
+      return "UNINSTALLED";
+    }
+  return "UNKNOWN";
+}
+
 void
 show_help (GOptionContext *context, const char *message)
 {
@@ -68,6 +91,41 @@ get_shell_settings (void)
   return g_settings_new_full (schema, NULL, NULL);
 }
 
+void
+print_extension_info (GVariantDict  *info,
+                      DisplayFormat  format)
+{
+  const char *uuid, *name, *desc, *path, *url, *author;
+  double state, version;
+
+  g_variant_dict_lookup (info, "uuid", "&s", &uuid);
+  g_print ("%s\n", uuid);
+
+  if (format == DISPLAY_ONELINE)
+    return;
+
+  g_variant_dict_lookup (info, "name", "&s", &name);
+  g_print ("  %s: %s\n", _("Name"), name);
+
+  g_variant_dict_lookup (info, "description", "&s", &desc);
+  g_print ("  %s: %s\n", _("Description"), desc);
+
+  g_variant_dict_lookup (info, "path", "&s", &path);
+  g_print ("  %s: %s\n", _("Path"), path);
+
+  if (g_variant_dict_lookup (info, "url", "&s", &url))
+    g_print ("  %s: %s\n", _("URL"), url);
+
+  if (g_variant_dict_lookup (info, "original-author", "&s", &author))
+    g_print ("  %s: %s\n", _("Original author"), author);
+
+  if (g_variant_dict_lookup (info, "version", "d", &version))
+    g_print ("  %s: %.0f\n", _("Version"), version);
+
+  g_variant_dict_lookup (info, "state", "d", &state);
+  g_print ("  %s: %s\n", _("State"), extension_state_to_string (state));
+}
+
 static int
 handle_version (int argc, char *argv[], gboolean do_help)
 {